using System;


public class LocationCD
{
  public static char GetCheckDigit(string code)
  {
    char result=' ';
    string transformedCode=GetTransformedCode(code);
    int weight=transformedCode.Length+1;
    int accumulator=0;
    for(int index=0;index<transformedCode.Length;index++)
    {
      accumulator+=(int)(transformedCode[index]-'0')*weight;
      weight--;
    }
    accumulator=accumulator%11;
    result=(accumulator==10)?'U':(char)('0'+(char)accumulator);
    return result;
  }

  public static string ApplyCheckDigit(string code)
  {
    if(code.Length==6)
      return string.Format("{0}{1}",code,GetCheckDigit(code));
    throw new Exception("incorrect length - must be 8");
  }

  public static bool Check(string code)
  {
    return (code[code.Length-1]==GetCheckDigit(code.Substring(0,code.Length-1)));
  }

  private static string GetTransformedCode(string code)
  {
    System.Text.StringBuilder result=new System.Text.StringBuilder();
    for(int index=0;index<code.Length;index++)
    {
      if(char.IsDigit(code[index]))
      {
        result.Append(code[index]);
      }
      else
      {
        result.Append(string.Format("{0:00}",code[index]-'A'+1));
      }
    }
    return result.ToString();
  }


}
